<template>
	<view class="side-nav-bar-wrap" v-show="show">
		<view class="side-nav-bar-mask" @tap.stop="maskClk" :class="{'outAni':isInOuting}"></view>
		<view class="side-nav-bar" :class="{'outAni':isInOuting}">
			<view class="user-msg">
				<view class="text-msg" @tap="toEditMsg">
					<view class="user-nickname">
						{{userInfo.nickName}}
						<image class="edit-icon" src="../../static/inputIcon.png" @tap="toEditMsg"></image>
					</view>
					<view class="user-tel">{{userInfo.phone}}</view>
				</view>
				<image class="user-avatar" :src="getImgUrl(userInfo.avatar)" @tap="toEditMsg"></image>
			</view>
			
			<view class="comment-num-msg">
				<view class="comment-num-item">
					<view class="item-num">{{userInfo.countOfLiked}}</view>
					<view class="item-name">被关注</view>
				</view>
				<view class="comment-num-item">
					<view class="item-num">{{userInfo.countOfEvaluating}}</view>
					<view class="item-name">发点评</view>
				</view>
				<view class="comment-num-item">
					<view class="item-num">{{userInfo.countOfEvaluated}}</view>
					<view class="item-name">被点评</view>
				</view>
			</view>
			<view class="nav-list">
				<view class="nav-item" @tap.stop="navTo('message')">
					<view class="nav-item-icon">
						<view class="msg-num-icon" v-if="unReadMsgNum > 0">{{unReadMsgNum > 99 ? '99+' : unReadMsgNum}}</view>
						<image class="nav-item-img" src="../../static/messageIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">消息</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>
				<view class="nav-item" @tap.stop="toConversations">
					<view class="nav-item-icon">
						<view class="msg-num-icon" v-if="unReadChatNum > 0">{{unReadMsgNum > 99 ? '99+' : unReadMsgNum}}</view>
						<image class="nav-item-img" src="../../static/chatIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">聊天对话</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>
				<view class="nav-item" @tap.stop="navTo('userDetail','?type=2')">
					<view class="nav-item-icon">
						<image class="nav-item-img" src="../../static/circleIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">我的点评</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>
				<view class="nav-item" @tap.stop="navTo('myFriends')">
					<view class="nav-item-icon">
						<image class="nav-item-img" src="../../static/friendsIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">朋友</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>
				<view class="nav-item" @tap.stop="navTo('setting')">
					<view class="nav-item-icon">
						<image class="nav-item-img" src="../../static/setIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">设置</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>
				<view class="nav-item" @tap.stop="navTo('agreement')">
					<view class="nav-item-icon">
						<image class="nav-item-img" src="../../static/editIcon.png"></image>
					</view>
					<view class="nav-item-content">
						<view class="nav-item-name">隐私协议</view>
						<image class="nav-item-arrow" src="../../static/rightArrowIcon.png"></image>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			}
		},
		computed: {
		  ...mapState(['userInfo','unReadMsgNum','unReadChatNum']),
		},
		watch: {
			show(newVal, oldVal) {
				if (newVal) {
					this.isInOuting = false
				}
			}
		},
		data() {
			return {
				isInOuting: false
			}
		},

		methods: {
			maskClk() {
				this.isInOuting = true
				setTimeout(() => {
					this.$emit('maskClk')
				}, 300)
			},

			navTo(pageName, query) {
				uni.navigateTo({
					url: `/pages/${pageName}/index${query ? query : ''}`
				})
			},
			toEditMsg() {
				this.$store.commit('setTempIdentityDesc','')
				uni.navigateTo({
					url: '/pages/userDetail/editUserMsg'
				})
			},
			toConversations(){
				uni.navigateTo({
					url: '/pages/message/conversations'
				})
			}
		}
	}
</script>


<style lang="less" scoped>
	.side-nav-bar-wrap {
		.side-nav-bar-mask {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, 0.3);
			z-index: 99;
			animation: fadeIn 0.3s forwards;

			&.outAni {
				animation: fadeOut 0.3s forwards;
			}
		}

		.side-nav-bar {
			position: fixed;
			top: 0;
			left: 0;
			width: 576rpx;
			height: 100%;
			background-color: #fff;
			z-index: 100;
			padding: 94rpx 46rpx;
			box-sizing: border-box;
			animation: slideIn 0.3s forwards;

			&.outAni {
				animation: slideOut 0.3s forwards;
			}

			.user-msg {
				display: flex;
				justify-content: space-between;

				.text-msg {
					.user-nickname {
						font-size: 40rpx;
						font-weight: 500;
						color: #323746;
						line-height: 56rpx;
						margin-bottom: 14rpx;
						.edit-icon{
                             height: 36rpx;
							 width: 36rpx;
							 margin-left: 20rpx;
						}
					}

					.user-tel {
						font-size: 26rpx;
						font-weight: 600;
						color: #9196A0;
						line-height: 30rpx;
					}
				}

				.user-avatar {
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
				}
			}

			.comment-num-msg {
				margin-top: 56rpx;
				display: flex;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #eee;

				.comment-num-item {
					margin-right: 50rpx;

					.item-num {
						font-size: 32rpx;
						font-weight: 500;
						color: #666666;
						line-height: 44rpx;
						margin-bottom: 2rpx;
					}

					.item-name {
						font-size: 26rpx;
						font-weight: 400;
						color: #9196A0;
						line-height: 36rpx;
					}
				}
			}

			.nav-list {
				margin-top: 32rpx;

				.nav-item {
					height: 100rpx;
					display: flex;
					align-items: center;

					.nav-item-icon {
						width: 60rpx;
						height: 60rpx;
						margin-right: 18rpx;
						position: relative;

						.msg-num-icon {
							width: 32rpx;
							height: 32rpx;
							border-radius: 50%;
							background-color: #FC7762;
							color: #fff;
							display: flex;
							align-items: center;
							justify-content: center;
							font-size: 18rpx;
							position: absolute;
							top: -4rpx;
							right: -10rpx;
						}

						.nav-item-img {
							width: 60rpx;
							height: 60rpx;
						}
					}


					.nav-item-content {
						flex: 1;
						height: 100rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding-right: 60rpx;
						border-bottom: 2rpx solid #eee;

						.nav-item-name {
							font-size: 30rpx;
							font-weight: 400;
							color: #323746;
							line-height: 42rpx;
						}

						.nav-item-arrow {
							width: 56rpx;
							height: 56rpx;
						}
					}
				}
			}

		}
	}

	@keyframes slideIn {
		0% {
			transform: translateX(-100%);
		}

		100% {
			transform: translateX(0);
		}
	}

	@keyframes fadeIn {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}

	@keyframes slideOut {
		0% {
			transform: translateX(0);
		}

		100% {
			transform: translateX(-100%);
		}
	}

	@keyframes fadeOut {
		0% {
			opacity: 1;
		}

		100% {
			opacity: 0;
		}
	}
</style>
